﻿using System;
using System.Web.UI;
using DevExpress.Web.ASPxMenu;
using System.Xml;
using SGRapidForm.Permission.Service.Interface;
using SGRapidForm.Common;
using DevExpress.Web.ASPxGridView;
using DevExpress.Web.ASPxEditors;
using SGRapidForm.Permission.Entity;
using System.Collections.Generic;
using DevExpress.Web.ASPxGridView;

namespace SGDemo.Permission
{
    public partial class AssociatedRoles : System.Web.UI.Page
    {
        private IPermissionService _permissionService = ServiceProxyFactory.Create<IPermissionService>("permissionservice");

        protected void Page_Load(object sender, EventArgs e)
        {
            JSManager.RegAjax(Header, this.GetType().BaseType);
        }

        /// <summary>
        /// 菜单项绑定事件 - 实现操作权限控制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void menuHeader_ItemDataBound(object sender, MenuItemEventArgs e)
        {
            IHierarchyData itemHierarchyData = (IHierarchyData)e.Item.DataItem;
            XmlElement element = (XmlElement)itemHierarchyData.Item;
        }

        /// <summary>
        /// 自定义GridView回调重新绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwList_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e)
        {
            gvwList.DataBind();
        }

        [AjaxPro.AjaxMethod]
        public bool BulkDelete(string userKeyid, string[] roleKeyids)
        {
            return _permissionService.UserRole_BulkDelete(userKeyid, roleKeyids);
        }
    }

    public class AssociatedRolesDataSource
    {
        private IPermissionService _permissionService = ServiceProxyFactory.Create<IPermissionService>("permissionservice");

        public List<Role> GetRoleByUserKeyid(string keyid)
        {
            return _permissionService.UserRole_GetRoleByUserKeyid(keyid);
        }
    }
}